package com.etoak.config;

import com.etoak.common.properties.ImageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

@Configuration
public class WebFluxConfig implements WebFluxConfigurer {

    @Autowired
    private ImageProperties imageProperties;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        String prefix = imageProperties.getPrefix().endsWith("/")
                ? imageProperties.getPrefix() + "**"
                : imageProperties.getPrefix() + "/**";

        String location = imageProperties.getLocation().endsWith("/")
                ? "file:" + imageProperties.getLocation()
                : "file:" +imageProperties.getLocation() + "/";

        registry.addResourceHandler(prefix).addResourceLocations(location);
    }
}
